package gestioneDatabase.Post;

import gestioneDatabase.SingleDatabaseElementUser;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import models.Post;

import org.w3c.dom.Element;
import org.xml.sax.SAXException;

/**
 * Permette l'inserimento di un post nel forum.
 * 
 */
public class PostInserter extends SingleDatabaseElementUser {

	private Post postToInsert;
	private PostInserterFiller postFiller = new PostInserterFiller();

	public PostInserter(Post postToInsert) {
		super();
		this.postToInsert = postToInsert;
	}

	@Override
	public void execute() {
		try {
			Element inputPost = open("DatabasePost", "Post");

			postFiller.fill(postToInsert, inputPost, doc);

			controller.writeIntoXMLFile(filepath);

		} catch (ParserConfigurationException pce) {
			pce.printStackTrace();
		} catch (TransformerException tfe) {
			tfe.printStackTrace();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} catch (SAXException sae) {
			sae.printStackTrace();
		}
	}

}
